<div class="layui-card-header layui-card">
    <span class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">首页</a>
        <a><cite>数据清理</cite></a>
    </span>
</div>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">数据清理</li>
            </ul>
            <div class="layui-tab-content">
                <form class="layui-form center">
                    <div class="layui-form-item">
                        <label class="layui-form-label">开始时间</label>
                        <div class="layui-input-inline">
                            <input type="text" name="startTime" id="startTime" autocomplete="off" placeholder="开始时间"
                                   class="layui-input">
                        </div>
                        <label class="layui-form-label">结束时间</label>
                        <div class="layui-input-inline">
                            <input type="text" name="endTime" id="endTime" autocomplete="off" placeholder="结束时间"
                                   class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">订单数据</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="item" lay-skin="primary" title="订单" value="payOrder"
                                   checked="">
                            <input type="checkbox" name="item" lay-skin="primary" title="订单通知" value="notify"
                                   checked="">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">商户数据</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="item" lay-skin="primary" title="商户结算" value="settRecord" checked="">
                            <input type="checkbox" name="item" lay-skin="primary" title="商户账户流水" value="mchHistory"
                                   checked="">
                            <input type="checkbox" name="item" lay-skin="primary" title="商户对账" value="bill" checked="">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">代理数据</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="item" lay-skin="primary" title="代理结算" value="settRecord" checked="">
                            <input type="checkbox" name="item" lay-skin="primary" title="代理账户流水" value="agentHistory"
                                   checked="">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">码商数据</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="item" lay-skin="primary" title="码商结算" value="passageSett"
                                   checked="">
                            <input type="checkbox" name="item" lay-skin="primary" title="码商订单" value="codeOrder"
                                   checked="">
                            <input type="checkbox" name="item" lay-skin="primary" title="码商账户流水"
                                   value="codeAccountHistory" checked="">
                            <input type="checkbox" name="item" lay-skin="primary" title="码商用户(已逻辑删除的)" value="codeUser"
                                   checked="">
                            <input type="checkbox" name="item" lay-skin="primary" title="码商二维码(已逻辑删除的)" value="codeInfo"
                                   checked="">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <label class="layui-form-label">系统数据</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="item" lay-skin="primary" title="系统日志" value="sysLog"
                                   checked="">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="button" class="layui-btn" lay-submit="" lay-filter="clean">清理</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>


<script>
    layui.use(['table', 'laydate'], function () {
        var form = layui.form
            , $ = layui.$
            , laydate = layui.laydate
            , layer = layui.layer
            , element = layui.element;

        element.render('breadcrumb', 'breadcrumb');

        form.on('submit(clean)', function (data) {
            var cleanItem = [];
            $('input[type=checkbox]:checked').each(function () {
                cleanItem.push($(this).val());
            });
            var startTime = $("#startTime").val();
            var endTime = $("#endTime").val();
            if (!startTime) {
                layer.alert("请选择开始时间");
                return false;
            }
            if (!endTime) {
                layer.alert("请选择结束时间");
                return false;
            }
            layer.confirm('确认清理吗？清理后数据不可恢复!', {icon: 3, title: '警告!'}, function (index) {
                $.ajax({
                    type: "POST",
                    url: layui.setter.baseUrl + '/clean/clean',
                    data: {
                        startTime: startTime,
                        endTime: endTime,
                        itemJson: JSON.stringify(cleanItem)
                    },
                    success: function (res) {
                        if (res.code == 0) {
                            layer.alert("清理成功！");
                        }
                    }
                });
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        laydate.render({
            elem: '#startTime'
            , type: 'datetime'
            , format: 'yyyy-MM-dd HH:mm:ss'
        });

        laydate.render({
            elem: '#endTime'
            , type: 'datetime'
            , format: 'yyyy-MM-dd HH:mm:ss'
        });
        // 渲染表单
        form.render();

    });

</script>